import numpy as np
from collections import Counter


def euclidean_distance(x1, x2):
    distance = np.sum((x1 - x2) ** 2)
    return np.sqrt(distance)


def knn(X, y, test_point, k):
    distances = []
    m = X.shape[0]

    for i in range(m):
        dist = euclidean_distance(X[i], test_point)
        distances.append((dist, y[i]))

    distances.sort(key=lambda x: x[0])

    neighbors_labels = [distances[i][1] for i in range(k)]

    most_common = Counter(neighbors_labels).most_common(1)[0][0]

    return most_common